package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements  IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书");
        System.out.println("请输入您要查找的图书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for(int i = 0;i < currentSize;i++) {
            Book book = bookList.getBook(i);//获取到书
            if(book.getName().equals(name)) {//判断该书是否存在
                System.out.println("本书信息如下: ");
                System.out.println(book);
                return;
            }
        }
        //没有找到
        System.out.println("书架中不存在" + name + "该书");
    }
}
